import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-06-27
 * Time: 22:10
 */
public class test2 {
    public List<Integer> findAnagrams(String s, String p) {
        List<Integer> ret = new ArrayList<>();
        int left = 0;
        int right = 0;
        int[] hash = new int[128];
        int n = s.length();
        for(int i=0;i<p.length();i++){
            char ch = p.charAt(i);
            hash[ch-'a']++;
        }
        while(right<n){
            char ch = s.charAt(right);
            hash[ch-'a']--;
            while(hash[ch-'a']<0){
                hash[s.charAt(left)-'a']++;
                left++;
            }
            if(right-left+1 == p.length()){
                ret.add(left);
            }
            right++;
        }
        return ret;
    }
}
